<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg">
  <head>
    <title>Creating XML nodes</title>
    <link rel="stylesheet" type="text/css" href="docbook-epub.css"/>
    <link rel="stylesheet" type="text/css" href="kawa.css"/>
    <script src="kawa-ebook.js" type="text/javascript"/>
    <meta name="generator" content="DocBook XSL-NS Stylesheets V1.79.1"/>
    <link rel="prev" href="Overall-Index.xhtml" title="Index"/>
    <link rel="next" href="XML-literals.xhtml" title="XML literals"/>
  </head>
  <body>
    <header/>
    <section class="sect1" title="Creating XML nodes" epub:type="subchapter" id="Creating-XML-nodes">
      <div class="titlepage">
        <div>
          <div>
            <h2 class="title" style="clear: both">Creating XML nodes</h2>
          </div>
        </div>
      </div>
      <p>The XML data model is similar to HTML, with one important addition:
XML tags may be <em class="firstterm">qualified names</em>, which are similar
to <a class="link" href="Namespaces.xhtml" title="Namespaces and compound symbols">compound symbols</a>.
</p>
      <p>You must do this to use the following types and functions:
</p>
      <pre class="screen">(require 'xml)
</pre>
      <p>The following types and functions assume:
</p>
      <pre class="screen">(require 'xml)
</pre>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667870656096" class="indexterm"/> <code class="function">make-element</code> <em class="replaceable"><code>tag</code></em> [<em class="replaceable"><code>attribute</code></em> <em class="replaceable"><code>...</code></em>] <em class="replaceable"><code>child</code></em> <em class="replaceable"><code>...</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Create a representation of a XML element, corresponding to
</p>
          <pre class="screen">&lt;<em class="replaceable"><code>tag</code></em> <em class="replaceable"><code>attribute</code></em>...&gt;<em class="replaceable"><code>child</code></em>...&lt;/<em class="replaceable"><code>tag</code></em>&gt;
</pre>
          <p>The result is a <code class="literal">TreeList</code>, though if the result context is a consumer
the result is instead "written" to the consumer.
Thus nested calls to <code class="literal">make-element</code> only result in a
single <code class="literal">TreeList</code>.
More generally, whether an <em class="replaceable"><code>attribute</code></em> or <em class="replaceable"><code>child</code></em> is includded
by copying or by reference is (for now) undefined.
The <em class="replaceable"><code>tag</code></em> should currently be a symbol, though in the future it should
be a qualified name.
An <em class="replaceable"><code>attribute</code></em> is typically a call to <code class="literal">make-attribute</code>,
but it can be any attribute-valued expression.
</p>
          <pre class="screen">(make-element 'p
	      "The time is now: "
	      (make-element 'code (make &lt;java.util.Date&gt;)))
</pre>
        </blockquote>
      </div>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667870644512" class="indexterm"/> <code class="function">element-name</code> <em class="replaceable"><code>element</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Returns the name (tag) of the element node, as a symbol (QName).
</p>
        </blockquote>
      </div>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667870641088" class="indexterm"/> <code class="function">make-attribute</code> <em class="replaceable"><code>name</code></em> <em class="replaceable"><code>value...</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Create an "attribute", which is a name-value pair.
For now, <em class="replaceable"><code>name</code></em> should be a symbol.
</p>
        </blockquote>
      </div>
      <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667870636736" class="indexterm"/> <code class="function">attribute-name</code> <em class="replaceable"><code>element</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Returns the name of the attribute node, as a symbol (QName).
</p>
        </blockquote>
      </div>
      <p class="synopsis" kind="Type"><span class="kind">Type</span><span class="ignore">: </span><a id="idm139667870633312" class="indexterm"/> <code class="function">comment</code></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Instances of this type represent comment values,
specifically including comments in XML files.
Comment nodes are currently ignored when printing using Scheme formatting,
though that may change.
</p>
        </blockquote>
      </div>
      <p class="synopsis" kind="Constructor"><span class="kind">Constructor</span><span class="ignore">: </span><a id="idm139667870630304" class="indexterm"/> <code class="function">comment</code> <em class="replaceable"><code>comment-text</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Create a comment object with the specified <em class="replaceable"><code>comment-text</code></em>.
</p>
        </blockquote>
      </div>
      <p class="synopsis" kind="Type"><span class="kind">Type</span><span class="ignore">: </span><a id="idm139667870626480" class="indexterm"/> <code class="function">processing-instruction</code></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Instances of this type represent “processing instructions”,
such as may appear in XML files.
Processing-instruction nodes are currently ignored when printing using
Scheme formatting, though that may change.
</p>
        </blockquote>
      </div>
      <p class="synopsis" kind="Constructor"><span class="kind">Constructor</span><span class="ignore">: </span><a id="idm139667870623216" class="indexterm"/> <code class="function">processing-instruction</code> <em class="replaceable"><code>target</code></em> <em class="replaceable"><code>contents</code></em></p>
      <div class="blockquote">
        <blockquote class="blockquote">
          <p>Crreate a processing-instruction object with the specified <em class="replaceable"><code>target</code></em>
(a simple symbol) and <em class="replaceable"><code>contents</code></em> (a string).
</p>
        </blockquote>
      </div>
    </section>
    <footer>
      <div class="navfooter">
        <p>
          Up: <a accesskey="u" href="XML-tools.xhtml">Working with XML and HTML</a></p>
        <p>
        Previous: <a accesskey="p" href="Creating-HTML-nodes.xhtml">Creating HTML nodes</a></p>
        <p>
        Next: <a accesskey="n" href="XML-literals.xhtml">XML literals</a></p>
      </div>
    </footer>
  </body>
</html>
